﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MM.Common.Base;
using MM.Common.DBBase;

namespace MMTJ
{
    public partial class FrmPassword : XtraForm
    {
        public FrmPassword()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string str = this.txtNew1.Text.Trim();
            string str2 = this.txtNew2.Text.Trim();
            if (str.Equals(str2))
            {
                Password password = new Password();
                string paramValue = password.Encrypting(this.txtOld.Text.Trim());
                str = password.Encrypting(str);
                DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("newpass", str), new InputDataParam("operid", SystemInfo.OperId), new InputDataParam("oldpass", paramValue) });
                try
                {
                    if (SystemInfo.DbData.ExecuteSql("UPDATE MXH_EMPLOYEE SET PASSWORD = :newpass WHERE EMP_ID = :operid AND PASSWORD = :oldpass", parms, 1) == 1)
                    {
                        MessageBox.Show("口令修改成功!");
                        base.Close();
                    }
                    else
                    {
                        MessageBox.Show("旧口令不正确!");
                        this.txtOld.Text = "";
                        this.txtOld.Focus();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show("口令修改出错\n" + exception.Message);
                }
            }
            else
            {
                MessageBox.Show("前后二次输入的新密码不一致。", "提示");
                this.txtNew1.Text = "";
                this.txtNew2.Text = "";
                this.txtNew1.Focus();
            }
        }
    }
}
